package com.sxfq.loansupermarket.backsystem.modular.doctorLooked.controller;

import com.sxfq.loansupermarket.backsystem.common.controller.BaseController;
import com.sxfq.loansupermarket.backsystem.core.log.LogManager;
import com.sxfq.loansupermarket.backsystem.core.log.factory.LogTaskFactory;
import com.sxfq.loansupermarket.backsystem.core.shiro.ShiroKit;
import com.sxfq.loansupermarket.backsystem.core.support.HttpKit;
import com.sxfq.loansupermarket.backsystem.modular.arrival.entity.CustomerInfo;
import com.sxfq.loansupermarket.backsystem.modular.arrival.entity.FirstCustomerInfo;
import com.sxfq.loansupermarket.backsystem.modular.arrival.service.ICustomerDetailsService;
import com.sxfq.loansupermarket.backsystem.modular.arrival.service.ICustomerService;
import com.sxfq.loansupermarket.backsystem.modular.doctorLooked.entity.*;
import com.sxfq.loansupermarket.backsystem.modular.doctorLooked.service.IDoctorDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 医生看诊/update
 *
 * @author py
 * @Date 2018年4月19日23:15:54
 */
@Controller
@RequestMapping("/doctorDetails")
public class DoctorDetailsController extends BaseController {
    @Autowired
    IDoctorDetailsService doctorDetailsService;

    @Autowired
    ICustomerDetailsService customerDetailsService;

    @Autowired
    ICustomerService customerService;

    private String PREFIX = "/doctorLooked/";

    @RequestMapping(value = "/doctor_seeDiagnosis/{id}/{tabId}")
    public String doctor_seeDiagnosis(@PathVariable String id, @PathVariable int tabId, Model model) throws Exception {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        CustomerInfo customerInfo = customerDetailsService.selectOneById(id); //当前记录的患者信息
        FirstCustomerInfo firstCustomerInfo = customerDetailsService.firstVisitInformation(customerInfo.getReservationsId()); //首次到店的患者信息
        if (firstCustomerInfo == null) {
            return "/doNoClose.html";
        }
        customerDetailsService.getCustomerInformationsList();
        customerInfo.setOrthodonticNumber(customerDetailsService.getorthodonticNumber(customerInfo.getReservationsId()));
        customerInfo.setFirstAppointmentPayService(firstCustomerInfo.getAppointmentPayService());
        customerInfo.setFirstArchiving(firstCustomerInfo.getArchiving());
        customerInfo.setFirstArrivalTime(firstCustomerInfo.getArrivalTime());
        customerInfo.setFirstFieldTc(firstCustomerInfo.getFieldTc());
        customerDetailsService.intodayOperation(customerInfo);
        model.addAttribute("occupationList", ShiroKit.getUser().getOccupationInfoList());
        model.addAttribute("refereeShipList", ShiroKit.getUser().getRefereeShipInfoList());
        model.addAttribute("tabId", tabId);
        model.addAttribute("customerInfo", customerInfo);
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        model.addAttribute("auditswitch", ShiroKit.getUser().getAuditswitch());
        model.addAttribute("roleNameLogin", ShiroKit.getUser().getRoleName());
        model.addAttribute("dealyesLogin", ShiroKit.getUser().getDealyes());
        model.addAttribute("isRefundAdmin", ShiroKit.getUser().getIsRefundAdmin());
        model.addAttribute("storeValue", ShiroKit.getUser().getOutpatientName());
        return PREFIX + "doctor_Details.html";
    }

    //病历
    @RequestMapping(value = "/medicalRecord", method = RequestMethod.POST)
    @ResponseBody
    public DotorCaseInfo medicalRecord(String reservationsId){
        DotorCaseInfo dotorCaseInfo=doctorDetailsService.medicalRecords(reservationsId);
        dotorCaseInfo.setMedicalUpPermission(doctorDetailsService.getMedicalUpPermission());
        return dotorCaseInfo;
    }

    //病历
    @RequestMapping(value = "/doctorFollow", method = RequestMethod.POST)
    @ResponseBody
    public DotorFollowsInfo doctorFollow(String reservationsId){
        DotorFollowsInfo dotorFollowsInfo=doctorDetailsService.doctorFollow(reservationsId);
        dotorFollowsInfo.setSfList(doctorDetailsService.getSfList());
        dotorFollowsInfo.setJgList(doctorDetailsService.getJgList());
        dotorFollowsInfo.setUserName(ShiroKit.getUser().getAccount());
        return dotorFollowsInfo;
    }


}